//
//  BaseVC.m
//  blocklyios
//
//  Created by steward on 2018/11/5.
//  Copyright © 2018 szltech. All rights reserved.
//

#import "BaseVC.h"
#import "ConstantUtils.h"

@interface BaseVC ()
@end

@implementation BaseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initBlueTooth];
}

-(void)initBlueTooth {
    //初始化BabyBluetooth 蓝牙库
    self.baby = [BabyBluetooth shareBabyBluetooth];
}

-(void)scanDevices {
    self.baby.scanForPeripherals().begin();
}

-(void)connectDevice {
    self.baby.having(self.mPeripheral)
        .connectToPeripherals()
        .discoverServices()
        .discoverCharacteristics()
        .readValueForCharacteristic()
        .discoverDescriptorsForCharacteristic()
        .readValueForDescriptors()
        .begin();
}

-(void)writeDataToDevice: (NSString *)str {
    if (self.mPeripheral && self.writeCharacteristic) {
        NSData *data = [ConstantUtils convertHexStrToData:str];
        if (data != nil) {
            [self.mPeripheral writeValue:data forCharacteristic:self.writeCharacteristic type:CBCharacteristicWriteWithoutResponse];
        }
    }
}

@end
